<template>
  <!-- 全屏组件 -->
  <div>
    <svg-icon :icon-class="isScreenFull ? 'exit-fullscreen' : 'fullscreen'" class="fullscreen" @click="toggleScreen" />
  </div>
</template>

<script>
// 导入全屏包
import screenfull from 'screenfull'
export default {
  name: 'ScreenFull',
  data() {
    return {
      isScreenFull: false // 控制是否是全屏
    }
  },
  mounted() {
    // 监听ESC退出，图片切换
    screenfull.on('change', () => {
      this.isScreenFull = screenfull.isFullscreen
    })
  },
  methods: {
    toggleScreen() {
      screenfull.toggle()
      this.isScreenFull = !this.isScreenFull
    }
  }
}
</script>

<style lang="scss" scoped>
.fullscreen {
  width: 20px;
  height: 20px;
  color: #fff;
  cursor: pointer;
}
</style>
